using UnityEngine;

//上下移动平台
public class MovingPlatform : MonoBehaviour
{
    public float moveSpeed = 2f; // 移动速度
    public float moveHeight = 5f; // 移动高度

    private Vector3 startPosition;
    private float journeyLength;
    private float startTime;

    void Start()
    {
        startPosition = transform.position; // 保存初始位置
        journeyLength = moveHeight;
        startTime = Time.time;
    }

    void Update()
    {
        float distanceCovered = (Time.time - startTime) * moveSpeed;
        float newY = Mathf.PingPong(distanceCovered, journeyLength);

        transform.position = startPosition + new Vector3(0, newY, 0);
    }
}

